﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Playables.FrameRate
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Globalization;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Playables
{
  [UsedByNativeCode("FrameRate")]
  [NativeHeader("Runtime/Director/Core/FrameRate.h")]
  internal struct FrameRate(uint frameRate = 0, bool drop = false) : IEquatable<FrameRate>
  {
    [Ignore]
    public static readonly FrameRate k_24Fps = new FrameRate(24U);
    [Ignore]
    public static readonly FrameRate k_23_976Fps = new FrameRate(24U, true);
    [Ignore]
    public static readonly FrameRate k_25Fps = new FrameRate(25U);
    [Ignore]
    public static readonly FrameRate k_30Fps = new FrameRate(30U);
    [Ignore]
    public static readonly FrameRate k_29_97Fps = new FrameRate(30U, true);
    [Ignore]
    public static readonly FrameRate k_50Fps = new FrameRate(50U);
    [Ignore]
    public static readonly FrameRate k_60Fps = new FrameRate(60U);
    [Ignore]
    public static readonly FrameRate k_59_94Fps = new FrameRate(60U, true);
    [SerializeField]
    private int m_Rate = (drop ? -1 : 1) * (int) frameRate;

    public bool dropFrame => this.m_Rate < 0;

    public double rate
    {
      get => !this.dropFrame ? (double) this.m_Rate : (double) -this.m_Rate * 0.999000999000999;
    }

    public bool IsValid() => this.m_Rate != 0;

    public bool Equals(FrameRate other) => this.m_Rate == other.m_Rate;

    public override bool Equals(object obj) => obj is FrameRate other && this.Equals(other);

    public static bool operator ==(FrameRate a, FrameRate b) => a.Equals(b);

    public static bool operator !=(FrameRate a, FrameRate b) => !a.Equals(b);

    public static bool operator <(FrameRate a, FrameRate b) => a.rate < b.rate;

    public static bool operator <=(FrameRate a, FrameRate b) => a.rate <= b.rate;

    public static bool operator >(FrameRate a, FrameRate b) => a.rate > b.rate;

    public static bool operator >=(FrameRate a, FrameRate b) => a.rate <= b.rate;

    public override int GetHashCode() => this.m_Rate;

    public override string ToString() => this.ToString((string) null, (IFormatProvider) null);

    public string ToString(string format) => this.ToString(format, (IFormatProvider) null);

    public string ToString(string format, IFormatProvider formatProvider)
    {
      if (string.IsNullOrEmpty(format))
        format = this.dropFrame ? "F2" : "F0";
      if (formatProvider == null)
        formatProvider = (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat;
      return UnityString.Format("{0} Fps", (object) this.rate.ToString(format, formatProvider));
    }

    internal static int FrameRateToInt(FrameRate framerate) => framerate.m_Rate;

    internal static FrameRate DoubleToFrameRate(double framerate)
    {
      uint frameRate1 = (uint) Math.Ceiling(framerate);
      if (frameRate1 <= 0U)
        return new FrameRate(1U);
      FrameRate frameRate2 = new FrameRate(frameRate1, true);
      return Math.Abs(framerate - frameRate2.rate) < Math.Abs(framerate - (double) frameRate1) ? frameRate2 : new FrameRate(frameRate1);
    }
  }
}
